export default class HashHistory {
  constructor(router) {
    this.router = router;
    window.addEventListener("hashchange", () => {
      this.transitionTo();
    });
  }

  getHash() {
    return location.hash.slice(1);
  }

  transitionTo(callback) {
    const hash = this.getHash();
    this.router.matcher.match(hash);
    callback?.();
  }

  push(path) {
    location.hash = "#" + path;
  }
}
